<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

/**
 * Improve and extend what the default CI_Unit_test class can do.
 * The main improvement is better display of test results
 */
class UnitTestReport
{
   
    /**
     *
     * Analyze test results data fromn CI_Unit_test and make determine total
     * number of passed/failed tests, total tests, as well as separate
     * successful and failed tests in their own arrays.
     * 
     * @param CI_Unit_test->result $result the results of some unit tests
     * @return array $report better organized data from $result
     */
    public function getSummary($result = null)
    {
       if (is_null($result))
          return 0;
       
       assert('!is_null($result) /* $results cannot be null */');
       
       $report = array();
       
       $report['total_tests'] = count($result);
       
       $report['total_failed'] = 0;
       $report['failed_tests'] = array();
       $report['passed_tests'] = array();

       
       //
       // Count total failed tests and put passed and failed tests in their
       // own array for easier parsing
       //
       foreach($result as $res)
       {
          if($res['Result'] == 'Failed')
          {
             $report['failed_tests'][] = $res;
             $report['total_failed']++;
          }
          else
          {
             $report['passed_tests'][] = $res;
          }
       }
          
       $report['total_passed'] = $report['total_tests'] - $report['total_failed'];
       
       return $report;
    }
}

/* End of file ReportSummary.php */